package com.hghivln.controller.system;

import com.hghivln.aspectj.annotation.Log;
import com.hghivln.aspectj.enums.BusinessType;
import com.hghivln.pojo.dto.CheckItemDto;
import com.hghivln.pojo.vo.AjaxResult;
import com.hghivln.service.CheckItemService;
import com.hghivln.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;

@RestController
@RequestMapping("system/checkItem")
public class CheckItemController {

    @Autowired
    private CheckItemService checkItemService;

    /**
     * 分页查询
     */
    @GetMapping("listCheckItemForPage")
    public AjaxResult listCheckItemForPage(CheckItemDto checkItemDto) {
        return checkItemService.listCheckItemForPage(checkItemDto);
    }


    /**
     * 添加
     */
    @PostMapping("addCheckItem")
    @Log(title = "添加检查项目",businessType = BusinessType.INSERT)
    public AjaxResult addCheckItem(@Validated CheckItemDto checkItemDto) {
        checkItemDto.setSimpleUser(ShiroUtils.getCurrentSimpleUser());
        return checkItemService.addCheckItem(checkItemDto);
    }

    /**
     * 修改
     */
    @PutMapping("updateCheckItem")
    @Log(title = "修改检查项目",businessType = BusinessType.UPDATE)
    public AjaxResult updateCheckItem(@Validated CheckItemDto checkItemDto) {
        checkItemDto.setSimpleUser(ShiroUtils.getCurrentSimpleUser());
        return checkItemService.updateCheckItem(checkItemDto);
    }

    /**
     * 删除
     */
    @DeleteMapping("deleteCheckItemByIds/{ids}")
    @Log(title = "删除检查项目",businessType = BusinessType.DELETE)
    public AjaxResult deleteCheckItemByIds(@PathVariable @Validated @NotEmpty(message = "要删除的检查项目ID不能为空")Long[] ids) {
        return checkItemService.deleteCheckItemByIds(ids);
    }

    /**
     * 根据ID查询一个检查项目信息
     */
    @GetMapping("getCheckItemById/{id}")
    public AjaxResult getCheckItemById(@PathVariable @Validated @NotEmpty(message = "检查项目ID不能为空") Long id) {
        return checkItemService.selectCheckItemById(id);
    }
}
